using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace Microsoft.WowAddonStudio.FrameXml.Design.Services.NameCreationService
{
	/// <summary>
	/// 
	/// </summary>
	public sealed class SimpleUniqueNumberGenerator : UniqueNumberGeneratorBase
	{
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleUniqueNumberGenerator"/> class.
        /// </summary>
        /// <param name="componentContainer">The component container.</param>
        public SimpleUniqueNumberGenerator(IContainer componentContainer) 
			: base(componentContainer)
		{

		}

		/// <summary>
		/// Generates the unique number.
		/// </summary>
		/// <param name="prefixName">Name of the prefix.</param>
		/// <returns></returns>
		public override int GenerateUniqueNumber(string prefixName)
		{
			int result = 1;
			if (ComponentContainer != null)
			{
                // Search for controls
				List<Component> controls = GetComponents(prefixName);
				if (controls.Count > 0)
				{
					int maxNum = result;
					controls.ForEach(ctrl =>
					                 	{
					                 		int num = GetNumericChars(ctrl.Site.Name.Replace
												(prefixName, String.Empty));
					                 		if (maxNum < num) maxNum = num;
					                 	});
					result = ++maxNum;
				}
			}
			return result;
		}
	}
}